package panel.loadWaiting
{
	import assists.HtmlText;
	import assists.Lang;
	import assists.TextFieldUtils;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.text.TextField;
	
	import inerface.ILoadingWait;
	
	public class LoadingWait extends Sprite implements ILoadingWait
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _loadIcon:MovieClip;
		private var _descText:TextField;
		private var _backGround:Shape;
		public function LoadingWait()
		{
			super();
		}
		
		public function init(stage:Stage, loader:ResourceLoader, lang:Lang,uri:URI = null):void
		{
			_stage = stage;
			_loader = loader;
			
			_loadIcon = new _loader.uiManager.loadIcon() as MovieClip;
			
			
			_descText = new TextField();
			_descText.autoSize = "left";
			_descText.mouseEnabled = false;
			TextFieldUtils.setHtmlText(_descText,HtmlText.formatSizeColor("拼了老命家加载中，\n      请稍候...",0xfff100));
			_backGround = new Shape();
			resize();
			this.addChild(_backGround);
			this.addChild(_loadIcon);
			this.addChild(_descText);
			draw();
		}
		
		private function draw():void
		{
			this.graphics.beginFill(0,0);
			this.graphics.drawRect(0,0,_stage.stageWidth,_stage.stageHeight);
			this.graphics.endFill();
		}
		
		public function showProcess(current:int,total:int):void
		{
			TextFieldUtils.setHtmlText(_descText,HtmlText.formatSizeColor("拼了老命家加载中\n" + int(current / total) * 100 + "%",0xfff100));
		}
		
		private function resize():void
		{
			_loadIcon.x = (_stage.stageWidth - _loadIcon.width) / 2;
			_loadIcon.y = (_stage.stageHeight - _loadIcon.height)/2;
			_descText.y = _loadIcon.y + _loadIcon.height;
			_descText.x = _loadIcon.x + (_loadIcon.width - _descText.width)/2;
			_backGround.graphics.beginFill(0,0.7);
			_backGround.graphics.drawRect(_descText.x,_descText.y,_descText.width,_descText.height);
			_backGround.graphics.endFill();
			
		}
		
		public function clear():void
		{
		}
	}
}